package gamble.money.dao;

import java.util.List;

import gamble.money.vo.MoneyDetailVo;
import gamble.money.vo.MoneyVo;
import gamble.money.vo.PageVO;

import org.mybatis.spring.support.SqlSessionDaoSupport;


public class MoneyDoaImpl extends SqlSessionDaoSupport implements MoneyDao {
	
	//getSqlSession()은 Transaction 관리를 지원 하지 않으므로 완성후 다시 변경할것.
	@Override
	public void getInsert(MoneyVo vo){
		int result = (Integer)getSqlSession().insert("inMoney", vo);
		if(result>0){
			int result2 = (Integer)getSqlSession().insert("upMoneyPlus", vo);
			if(result2 ==0){
				System.out.println("Transaction Fail ㅠㅠ");
			}
		}
		
	}
	

	@SuppressWarnings("unchecked")
	@Override
	public List<MoneyDetailVo> getList(PageVO pv) {
		List<MoneyDetailVo> list= getSqlSession().selectList("getlist", pv);
		return list;
	}

	@Override
	public int getCount(String id) {
		int result = (Integer)getSqlSession().selectOne("getCount", id);
		return result;
	}

	@Override
	public int getMoney(String id) {
		int money = (Integer)getSqlSession().selectOne("getMoney", id);
		return money;
	}
	//getSqlSession()은 Transaction 관리를 지원 하지 않으므로 완성후 다시 변경할것.
	@Override
	public String goWithdrawal(MoneyVo vo){
		int result =(Integer)getSqlSession().insert("gowithdrawal", vo);
		if(result >0){
			int result2 = getSqlSession().insert("upMoney", vo);
			if(result2 == 0){
				return "fail";
			}
		}else {
			return "fail";
		}
		return "success";
		
	}
}
